package com.nfha.algorithm.geo.navigation;

import java.awt.geom.Point2D;
import java.util.Date;
import java.util.List;

public class GeoPoint {

	public static double pi = 3.1415926535897932384626;
	
	
	  String name;
	
	 double lat,lon;
	
	 double x,y;
	
	
	 
	 


	public GeoPoint(String name, double lon, double lat) {
		super();
		this.name = name;
		this.lat = lat;
		this.lon = lon;
		
		double[] xy=millierConvertion(lon, lat);
		this.x=xy[0];
		this.y=xy[1];
		
	}






	@Override
	public String toString() {
		return "GeoPoint [name=" + name + ", lat=" + lat + ", lon=" + lon + ", x=" + x + ", y=" + y + "]";
	}


	
	public static double[] millierConvertion(double lon, double lat)  
    {  
         double L = 6381372 * Math.PI * 2;//地球周长  
         double W=L;// 平面展开后，x轴等于周长  
         double H=L/2;// y轴约等于周长一半  
         double mill=2.3;// 米勒投影中的一个常数，范围大约在正负2.3之间  
         double x = lon * Math.PI / 180;// 将经度从度数转换为弧度  
         double y = lat * Math.PI / 180;// 将纬度从度数转换为弧度  
         y=1.25 * Math.log( Math.tan( 0.25 * Math.PI + 0.4 * y ) );// 米勒投影的转换  
         // 弧度转为实际距离  
         x = ( W / 2 ) + ( W / (2 * Math.PI) ) * x;  
         y = ( H / 2 ) - ( H / ( 2 * mill ) ) * y;  
         double[] result=new double[2];  
         result[0]=x;  
         result[1]=y;  
         return result;  
    }  


	
	 public static double transformLat(double x, double y) {  
	        double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y  
	                + 0.2 * Math.sqrt(Math.abs(x));  
	        ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;  
	        ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;  
	        ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;  
	        return ret;  
	    }  

	    public static double transformLon(double x, double y) {  
	        double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1  
	                * Math.sqrt(Math.abs(x));  
	        ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;  
	        ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;  
	        ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0  
	                * pi)) * 2.0 / 3.0;  
	        return ret;  
	    }  


	
	
	
	
	
}
